package com.taorenqi.data.requestmsgtoken;

import android.content.Context;

import com.taorenqi.data.common.BasePageableResponse;
import com.taorenqi.data.entity.login.CodeDataEntity;
import com.taorenqi.data.entity.login.LoginEntity;

import rx.Observable;
import rx.Subscriber;

/**
 * Created by Administrator on 2017-06-12.
 */

public class RegisterDataHttpRequest extends HttpRequestToken {

    private static RegisterDataHttpRequest instants;
    private RegisterDataService service;

    private RegisterDataHttpRequest(Context context) {
        super(context);
        service = retrofit.create(RegisterDataService.class);
    }

    public static RegisterDataHttpRequest getInstance(Context context){
        if (instants == null){
            instants = new RegisterDataHttpRequest(context);
        }

        return instants;
    }


    /**
     * 用于注册
     *
     * @param subscriber 由调用者传过来的观察者对象
     * @param mobile      手机号
     * @param password    密码
     * @param device      设备
     */
    public void postRegister(Subscriber<BasePageableResponse<LoginEntity>> subscriber, String mobile,
                             String password, String vcode, String spreadCode, String device, String sign, int isqy) {

        Observable observable = service.postRegister(mobile, password,vcode,spreadCode,device,sign,isqy)
                .map(new HttpResultFunc<BasePageableResponse<LoginEntity>>());

        toSubscribe(observable, subscriber);
    }


    /**
     *
     * 修改密码
     * @param subscriber 由调用者传过来的观察者对象
     * @param mobile      手机号
     * @param password    密码
     * @param sign
     */
    public void postModifyPwd(Subscriber<BasePageableResponse<CodeDataEntity>> subscriber, String mobile, String password, String vcode,String sign) {

        Observable observable = service.postModifyPwd(mobile, password,vcode,sign)
                .map(new HttpResultFunc<BasePageableResponse<CodeDataEntity>>());

        toSubscribe(observable, subscriber);
    }

}
